package com.my.springboot.tuling.concurrent.demo.priority;

/**
 * 等待调用join方法的线程结束之后，程序再继续执行，一般用于等待异步线程执行完结果之
 * 后才能继续运行的场景。
 */
public class ThreadJoinDemo {

    public static void main(String[] sure) throws InterruptedException {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t begin");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t finished");
            }
        });
        long start = System.currentTimeMillis();
        t.start();
        //主线程等待线程t执行完成
        t.join();

        System.out.println("执行时间:" + (System.currentTimeMillis()-start));
        System.out.println("Main finished");
    }
}